<%-- 
    Document   : statistics
    Created on : 13-mar-2012, 16:03:22
    Author     : Alvaro
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="classes.product"%>
<%@page import="classes.AdminDB"%>
<%@page import="classes.graph"%>
<%ArrayList<product> productos = (ArrayList<product>) session.getAttribute("listaDeproductos");%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Statistics | Admin</title>
        <script type="text/javascript" src="../js/jscharts.js"></script>
        <link rel="stylesheet" type="text/css" href="../css/admin.css" />
    </head>
    <body>
        <h1 align="center" class="tituloStats">Stats</h1>
        <h2 align="center" class="tituloStats">Bestsellers</h2>
        <form name="numberproductos" method="post" action="statsBestsellers.jsp">
            Number of products to show: <input name="number" type="text" size="5" maxlength="5">
            <input type="submit" name="numberprod" value="OK">
        </form>

        <script>
            var myData = new Array();
        </script>

        <%
            int i = 0, numberProd = 0;
            String[] arrayX = new String[100];
            try{
            numberProd = Integer.parseInt(request.getParameter("number"));
                       }
            catch
                (NumberFormatException nfe){}
            
            int[] arrayY = new int[100];

            String sentencia = "";

            graph g = new graph();
            AdminDB adb = new AdminDB();
            g.getPointsX(adb.getConnection());
            g.getPointsBestsellersY(adb.getConnection());
            int total = 0;
            total = g.getNumberProducts(adb.getConnection());
        %>
        There are: <%=total%> products in our database.
        <%

                    if (productos == null) {%>
        <form name="form1" method="post" action="/ShopOnline/listProducts">
            <input type="submit" name="cargasProd" id="cargasProd" value="Load">
            <input type="hidden" name="stats" value="stats">
        </form>	
        <%} else {
            while (i < numberProd) {
                arrayX = g.getPointsX(adb.getConnection());
                arrayY = g.getPointsBestsellersY(adb.getConnection());
                if (i != numberProd-1) {
                    sentencia += "(['" + arrayX[i] + "'," + arrayY[i] + "]),";
                } else {
                    sentencia += "(['" + arrayX[i] + "'," + arrayY[i] + "])";
                }
                i = i + 1;
                System.out.println("Grafica Bestsellers= " + sentencia);
                //sentencia += "(['"+arrayX[i]+","+arrayY[i]+"])";
                }%>




        <div id="graph">Loading graph...</div>

        <p>
            <%
    }%>








        </p>
        <h2 align="center" class="Center">More stats </h2>
        <div align="center">
            <table width="15%" border="0" class="titulo">
                <tr>
                    <th scope="col"><p align="center" class="Center"><a href="statsBestsellers.jsp">Bestsellers</a></p>
                <p align="center" class="Center"><a href="statsStock.jsp">Stock</a></p>
                <p align="center" class="Center"><a href="statsDay.jsp">Sales</a></p>
                <p align="center" class="Center"><a href="statsBestCustomers.jsp">Customers</a></p></th>
                </tr>
            </table>
        </div>
        <p align="center" class="Center"><a href="statistics.jsp">back</a></p>
        <h2 align="center" class="Center"><a href="Admin.jsp"><img src="../images/b_prev.png" alt="back" width="40" height="40" align="absmiddle">Admin</a></h2>
        <p>&nbsp;</p>
        <script type="text/javascript">
        myData = Array(<%=sentencia%>);
        //Array: primer valor: x | segundo valor: y(veces comprado)
        var colors = ['#AF0202'];
        var myChart = new JSChart('graph', 'bar');
        myChart.setDataArray(myData);
        myChart.setTitle('Bestsellers');
        myChart.setTitleColor('#8E8E8E');
        myChart.setTitleFontSize(11);
        myChart.setAxisNameX('');
        myChart.setAxisNameY('');
        myChart.setAxisColor('#C4C4C4');
        myChart.setAxisValuesColor('#343434');
        myChart.setAxisPaddingLeft(80);
        myChart.setAxisPaddingRight(10);
        myChart.setAxisPaddingTop(50);
        myChart.setAxisPaddingBottom(40);
        myChart.setAxisValuesNumberX(6);
        myChart.setGraphExtend(true);
        myChart.setGridColor('#c2c2c2');
        myChart.setLineWidth(6);
        myChart.setLineColor('#9F0505');
        myChart.setSize(2520, 321);
        myChart.setBackgroundImage('chart_bg.jpg');
        myChart.draw();
        </script>
    </body>
</html>
